﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Snake.Test;
using Snake;
namespace Snake.ORM.WebTest.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to ASP.NET MVC!";
            var con = @"Data Source=.\sql2008;Initial Catalog=Snake;Persist Security Info=True;User ID=sa;Password=sa";
            var session = (Session)new Factory(con).Create();

            //snake 一级缓存：一次会话取同一个实体只读一次库
            var w1 = session.Get<Work>(1);
            var w2 = session.Get<Work>(1);

            //普通的添加
            var work = new Work();
            work.Name = "强淫行1111111";
            session.Save(work);

            //普通查询
            var e1 = session.GetAll<Employee>().Where(a => a.Name.Contains("妹子"));

            //两次left join查询、orderyBy、 skip、 take 关键词

            //目前翻译的关键词：where、OrderBy、ThenBy、OrderByDescending、ThenByDescending、Take、Skip
            var e2 = session.GetAll<Employee>().Where(a => a.Department.Work.Name.Contains("编程"))
                                               .OrderBy(a => a.Name)
                                               .Skip(2)
                                               .Take(1);


            return View();
        }

        public ActionResult About()
        {
            return View();
        }
    }
}
